self.onmessage = function(event) {
  const { task, data } = event.data;
  if (task === 'my-calc') {
    const result = performHeavyComputation(data);
    self.postMessage(result);  // 将计算结果返回给主线程
  }
};

function performHeavyComputation(data) {
  let result = 0;
  for (let i = 0; i < data; i++) {
    result += i;
  }
  return result;
}